<template>
  <section>
    <el-table :data="examineList">
      <el-table-column type="index" label="序号"/>
      <el-table-column prop="name" label="标题"></el-table-column>
      <el-table-column label="操作" width="180" fixed="right">
        <template slot-scope="scope">
          <span v-if="scope.row.hasReportData">已生成报告数据</span>
          <el-button @click="makeDataBtn(scope.row)" size="mini" type="primary">生成数据</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :visible.sync="createUserDialog">
      <create-user :newName="selUser" v-on:cancel="cancelBtn"></create-user>
    </el-dialog>
  </section>
</template>

<script>
  import createUser from '@/components/createUser'
  import DateFormat from '@/common/date-formater'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler.js'
  export default {
    name: "makeReportDataByExamine",
    components:{createUser},
    data() {
      return {
        users:[],
        selUser:null,
        examineList:null,
        formRow:false,
        createUserDialog:false,
      }
    },
    created(){
      //获取所有已完成体检列表
      this.getExamineList()
      console.log(this.department)
    },
    watch:{
      selUser(nv,ov){
        console.log('selUser',nv)
        if(typeof(nv) === "string"){
          //跳出新建用户的对话框
          this.createUserDialog=true
        }
      }
    },
    computed:{
      ...mapGetters(['department']),
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getExamineList(pageNo){
        this.fetch({name:"getExamineList",data:{state:'3'}})
          .then(res=>{
            console.log(res.content)
            this.examineList=res.content
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      makeDataBtn(row){
        console.log(row)
        this.$prompt('新建一个报告数据，请输入标题', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPlaceholder:'*提交之后不能修改'
        }).then(({ value }) => {
          console.log('去新建啦！',value)
          let data={currDate:this.formatDate(row.date)}
          this.createReportDataByExamine(row.id,value,data)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          })
        })
      },
      formatDate(a){
        console.log('时间格式——————————————————————————',a)
        return DateFormat.format(a)
      },
      createReportDataByExamine(examineId,title,data){
        console.log(examineId,title,data)
        this.fetch({name:"createReportDataByExamine",data:{examineId,title,data},method:'post'})
          .then(res=>{
            this.$emit('cancel',res)
            console.log(res)
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      cancelBtn(e){
        this.createUserDialog=false
        this.selUser=e
      },
    }
  }
</script>

<style scoped>

</style>
